package com.ziyucoding.springboot.labs.lab4.concurrentdemo.example.singleton;

import com.ziyucoding.springboot.labs.lab4.concurrentdemo.annoations.NotRecommend;
import com.ziyucoding.springboot.labs.lab4.concurrentdemo.annoations.ThreadSafe;

/**
 * 单例模式
 * 懒汉模式：单例实例在第一次使用时进行创建
 *
 * @author ziyucoding
 * @date 2022-10-26
 **/
@ThreadSafe
@NotRecommend
public class SingletonExample3 {

    /**
     * 单例
     */
    private static SingletonExample3 instance = null;

    private SingletonExample3() {

    }

    /**
     * 获取实例
     * <p>
     * synchronized 性能开销大
     *
     * @param
     * @return SingletonExample3
     **/
    public static synchronized SingletonExample3 getInstance() {
        if (null == instance) {
            instance = new SingletonExample3();
        }
        return instance;
    }
}
